package com.jzh.cmhSystem.biz.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.jzh.cmhSystem.biz.EnterpriseService;
import com.jzh.cmhSystem.entity.Enterprise;
import com.jzh.cmhSystem.mapper.EnterpriseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EnterpriseServiceImpl implements EnterpriseService {
    @Autowired
    private EnterpriseMapper enterpriseMapper;

    public List<Enterprise> getEnterprisesWithSectionsBySectionName(String sectionName) {
        return enterpriseMapper.selectEnterprisesWithSections(sectionName);
    }

    @Override
    public int addEnterprise(Enterprise enterprise) {
        enterpriseMapper.insert(enterprise);
        return enterprise.getId();
    }

    @Override
    public List<Enterprise> getEnterprisesWithSectionsBySectionNameAndEnterpriseId(String sectionName, int enterpriseId) {

        return enterpriseMapper.getEnterprisesWithSectionsBySectionNameAndEnterpriseId(sectionName, enterpriseId);
    }

    @Override
    public List<Enterprise> getEnterpriseByUserId(int userId) {
        QueryWrapper<Enterprise> queryWrapper = new QueryWrapper<Enterprise>();
        queryWrapper.eq("admin_id", userId);
        return enterpriseMapper.selectList(queryWrapper);
    }

    @Override
    public void updataByEnUserId(Enterprise enterprise) {
        UpdateWrapper<Enterprise> updateWrapper = new UpdateWrapper<Enterprise>();
        updateWrapper.lambda().eq(Enterprise::getAdminId, enterprise.getAdminId()).set(Enterprise::getName, enterprise.getName()).set(Enterprise::getContact, enterprise.getContact());
        enterpriseMapper.update(updateWrapper);
    }


}
